#include <vector>
using namespace std;

int wiggleMaxLength(vector<int> &nums) {
  if (nums.size() < 2)
    return nums.size();
  int pre_diff = 0;
  int cur_diff = 0;
  int res = 1;
  for (int i = 1; i < nums.size(); ++i) {
    cur_diff = nums[i] - nums[i - 1];
    if ((pre_diff >= 0 && cur_diff < 0) || (pre_diff <= 0 && cur_diff > 0)) {
      res++;
      pre_diff = cur_diff;
    }
  }
  return res;
}